﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> 
        <title>textarea字数限制 练习代码多有参考网络 by ahuinan</title> 
        <script language="JavaScript" type="text/javascript">     
            var TextUtil = new Object(); 
            TextUtil.NotMax = function(oTextArea){ 
                var maxText = oTextArea.getAttribute("maxlength"); 
                if(oTextArea.value.length > maxText){ 
                        oTextArea.value = oTextArea.value.substring(0,maxText); 
                        alert("超出限制"); 
                } 
            } 
        </script> 
    </head> 
    <body> 
        <textarea rows="10" cols="60" onpropertychange="TextUtil.NotMax(this)" maxlength="20"></textarea> 
    </body> 
</html> 
